<template>
    <div>
        <el-row>
            <el-col :span="7" :offset="9">
                <el-form ref="form" label-width="50px">
                    <el-form-item label="邮箱">
                        <el-input v-model="email"
                                  placeholder="请再输入邮箱"
                                  prefix-icon="el-icon-user"
                                  clearable>>
                        </el-input>
                    </el-form-item>
                    <el-form-item label="密码">
                        <el-input v-model="password"
                                  placeholder="请再输入密码"
                                  prefix-icon="el-icon-lock"
                                  show-password
                                  clearable>>
                        </el-input>
                    </el-form-item>
                    <el-form-item>
                        <div style="text-align: center">
                            <el-button type="success" @click="login">
                                登录
                            </el-button>
                            <el-button @click="$router.push('/sign-up')">
                                注册
                            </el-button>
                        </div>
                    </el-form-item>
                </el-form>
            </el-col>
        </el-row>
    </div>
</template>
<script>
export default {
    components: {},
    data() {
        return {
            email:"",
            password:"",
        }
    },
    methods: {
        login() {
            let email = this.email;
            let password = this.password;
            if (email.length === 0 || password.length === 0) {
                this.$notify.error({
                    title: "请填写登录信息",
                    message: ""
                })
                return;
            }
            this.$axios({
                url: "/api/user/login",
                method: "post",
                data: {
                    email: email,
                    password: password
                }
            }).then((res) => {
                console.log(res)
                if (res.data.success) {
                    if (res.data.serviceCode >= 0) {
                        localStorage.setItem("token", res.data.result);
                        this.$router.push("/index")
                    } else {
                        this.$notify.error({
                            title: res.data.errorMessage,
                            message: res.data.errorDetail
                        })
                    }
                } else {
                    this.$notify.error({
                        title: res.data.errorMessage,
                        message: res.data.errorDetail
                    })
                }
            })
        }
    },
}
</script>
<style>

</style>